/**
 * 
 */
package com.sfeir.client.tetriselement;

import static com.sfeir.client.util.Constants.SQUARE_SIZE;

import com.google.gwt.canvas.dom.client.Context2d;
import com.google.gwt.dom.client.ImageElement;
import com.google.gwt.user.client.ui.Image;
import com.sfeir.client.util.Constants;
import com.sfeir.canvas.util.client.ResourceManager;

/**
 * @author Fran�ois LAROCHE
 * 
 */
public class TObject extends TetrisObject {

	private static final boolean[][] matrix1 = new boolean[4][4];
	private static final boolean[][] matrix2 = new boolean[4][4];
	private static final boolean[][] matrix3 = new boolean[4][4];
	private static final boolean[][] matrix4 = new boolean[4][4];

	static {
		matrix1[1][1] = true;
		matrix1[2][0] = true;
		matrix1[2][1] = true;
		matrix1[2][2] = true;

		matrix2[1][1] = true;
		matrix2[2][0] = true;
		matrix2[2][1] = true;
		matrix2[3][1] = true;

		matrix3[2][0] = true;
		matrix3[2][1] = true;
		matrix3[2][2] = true;
		matrix3[3][1] = true;
 
		matrix4[1][1] = true;
		matrix4[2][1] = true;
		matrix4[2][2] = true;
		matrix4[3][1] = true;
	}

	private final Image image;
	/**
	 * @param shapeColor
	 * @param lineColor
	 */
	public TObject(ResourceManager manager) {
		super(manager.getImage(Constants.KEY_IMAGE_T_PART), matrix1, matrix2, matrix3, matrix4);
		this.image = manager.getImage(Constants.KEY_IMAGE_T);
	}

	@Override
	protected void draw(Context2d ctx) {
		ctx.drawImage(ImageElement.as(this.image.getElement()), -3 * SQUARE_SIZE / 2, -3 * SQUARE_SIZE / 2);
	}

	@Override
	protected int adjustXToFitCase() {
		return -SQUARE_SIZE / 2;
	}

	@Override
	protected int adjustYToFitCase() {
		return -SQUARE_SIZE / 2;
	}

	@Override
	protected int adjustXToFitCenter() {
		return 0;
	}

	@Override
	protected int adjustYToFitCenter() {
		return SQUARE_SIZE / 2;
	}

}
